/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

package hirt;

/**
 * Loader is a boot strap that automatically gets executed when running the hirt
 * project as a .jar. Its arguments/parameters determines what is loaded (client,
 * server, or both).
 * @author adieffe
 */
public class Loader
{
    /**
     * String that holds the first parameter pasted into the Loader.
     * "client" to load a client.
     * "server" to load a server.
     * "clientandserver" to load both.
     */
    String programParameter1;

    /**
     * Constructor.
     * @param arguments determines what other modules are loaded ("client" "server" "clientandserver").
     */
    public Loader( String arguments )
    {
        programParameter1 = arguments;
        run();
    }

    /**
     * Thread for executing the server and client separately.
     */
    public void run()
    {
        if( programParameter1 != null )
        {
            programParameter1 = programParameter1.toLowerCase();

            System.out.println( "Running with parameters:  " + programParameter1 );
        }
        else
        {
            return;
        }

        if( programParameter1.equals( "server" ) )
        {
            // Just load a server
            java.awt.EventQueue.invokeLater( new Runnable()
            {
                public void run()
                {
                    ServerParent1 serverParent = new ServerParent1( "" );
                    serverParent.start();
                }
            } );
        }
        else
        if( programParameter1.equals( "client" ) )
        {
            // Just open a client.
            java.awt.EventQueue.invokeLater( new Runnable()
            {
                public void run()
                {
                    MainFrame mainFrame = new MainFrame();
                    //mainFrame.setVisible( true );
                }
            } );
        }
        else
        if( programParameter1.equals( "clientandserver" ) )
        {
            // Open both a local server and a client.
            java.awt.EventQueue.invokeLater( new Runnable()
            {
                public void run()
                {
                    ServerParent1 serverParent = new ServerParent1( "" );
                    serverParent.start();

                    MainFrame mainFrame = new MainFrame();
                    //mainFrame.setVisible( true );
                }
            } );
        }
    }

    /**
    * main function that is loaded when run as a .jar or otherwise.
    * @param args the command line arguments
    */
    public static void main( String args[] )
    {
        String tempProgramParameter1 = args[0];
        new Loader( tempProgramParameter1 );
    }
}
